import request from '@/utils/request'

// 用户管理相关的API请求函数
const api_name = '/admin/acl/user'

export function getInfo(token) {
  return request({
    url: '/ssoUsers/getInfo',
    method: 'get',
    params: { token }
  })
}

// 获取当前登录用户信息
export function getCurrentUser() {
  return request({
    url: '/api/system/user/current',
    method: 'get'
  })
}

// 获取当前登录用户ID
export function getCurrentUserId() {
  return request({
    url: '/api/system/user/current/id',
    method: 'get'
  })
}

export function getPageUser(pageNum, pageSize) {
  return request({
    url: `/ssoUsers/getPageUsers/${pageNum}/${pageSize}`,  
    method: 'get',
  });
}

// 获取用户已分配角色和所有角色列表
export function getUserRoles(userId) {
  return request({
    url: `${api_name}/toAssign/${userId}`,
    method: 'get'
  })
}

// 给用户分配角色
export function assignRoles(userId, roleIds) {
  return request({
    url: `${api_name}/doAssign`,
    method: 'post',
    params: {
      userId,
      roleId: roleIds
    }
  })
}

// 移除角色
export function removeRole(userId, roleId) {
  return request({
    url: `/admin/acl/user/removeRole/${userId}/${roleId}`,
    method: 'delete'
  })
}

// 删除用户
export function deleteUser(id) {
  return request({
    url: `/ssoUsers/deleteUser/${id}`,
    method: 'delete'
  })
}

export function logout(token) {
  return request({
    url: '/login/logout',
    method: 'post',
    params: { token }
  })
}

// 导出默认对象便于在其他地方使用
export default {
  getInfo,
  getPageUser,
  getUserRoles,
  assignRoles,
  deleteUser,
  logout
}




